#include <bits/stdc++.h>
using namespace std;
int he(long long k) {
  int sum = 0;
  while (k > 0) {
    sum += k % 10;
    k /= 10;
  }
  return sum;
}

int main() {
  long long n;
  cin >> n;
  do {
    int r = he(n); // 求出n的各位数字之和
    n = r;
  } while (n >= 10);
  cout << n;
  return 0;
}